//
//  ConfigCellNormalView.m
//  JinganMindCloud
//
//  Created by JinganMac on 2020/7/3.
//  Copyright © 2020 JingAn. All rights reserved.
//

#import "ConfigCellNormalView.h"



@interface ConfigCellNormalView ()
@property (nonatomic, strong) UILabel *leftTitleView;
@property (nonatomic, strong) UILabel *rightContentView;

@end

@implementation ConfigCellNormalView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self addSubview:self.leftTitleView];
        [self addSubview:self.rightContentView];
    }
    return self;
}

-(void)layoutSubviews{
    [_leftTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (self.viewConfiSets.normalType==1) {
            make.left.top.mas_equalTo(self);
            make.width.mas_equalTo(self.leftViewWidth);
        }else{
            make.left.top.bottom.mas_equalTo(self);
            make.width.mas_equalTo(self.leftViewWidth);
        }
    }];
    
    [_rightContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self.leftTitleView.mas_right);
    }];
    
}

-(UILabel *)leftTitleView{
    if (!_leftTitleView) {
        _leftTitleView = [UILabel new];
        _leftTitleView.textColor = [UIColor colorWithHexString:@"#AEAEAE"];
        _leftTitleView.font = [UIFont systemFontOfSize:13.];
        _leftTitleView.numberOfLines = 0;
    }
    return _leftTitleView;
}

-(UILabel *)rightContentView{
    if (!_rightContentView) {
        _rightContentView = [UILabel new];
        _rightContentView.textColor = [UIColor colorWithHexString:@"#535353"];
        _rightContentView.font = [UIFont systemFontOfSize:13.];
        _rightContentView.numberOfLines = 0;
    }
    return _rightContentView;
}

-(void)setViewConfiSets:(CellSubViewsConfigSetting *)viewConfiSets{
    [super setViewConfiSets:viewConfiSets];
    self.leftTitleView.text = viewConfiSets.cTitleValue;
    if (viewConfiSets.tFontColor) {
        NSString *hexColor = [NSString stringWithFormat:@"#%@",viewConfiSets.tFontColor];
        self.rightContentView.textColor = [UIColor colorWithHexString:hexColor];
    }
    if (viewConfiSets.tFontSize) {
        self.rightContentView.font =viewConfiSets.tFontBlod?[UIFont boldSystemFontOfSize:viewConfiSets.tFontSize]:[UIFont systemFontOfSize:viewConfiSets.tFontSize];
    }
    if (viewConfiSets.couldTouch) {
        self.rightContentView.userInteractionEnabled = YES;
        self.tapGestureRecognizer = [[UITapGestureRecognizer alloc]init];
        [self.rightContentView addGestureRecognizer:self.tapGestureRecognizer];
    }
    if (!viewConfiSets.canLinebreak) {
        self.rightContentView.numberOfLines = 1;
        self.leftTitleView.numberOfLines = 1;
    }
}

-(void)setBaseVaule:(NSString *)baseVaule{
    self.rightContentView.text = baseVaule;
    
    if (self.viewConfiSets.regularDes.length>0) {
        NSString *str = baseVaule;
        NSString *reg = self.viewConfiSets.regularDes;
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str];
        NSRange range = [str rangeOfString:reg options:NSRegularExpressionSearch];
        if (range.location != NSNotFound) {
            NSString *subStr = [str substringWithRange:range];
            NSLog(@"富文本%@", subStr);
            if (self.viewConfiSets.attributeColor.length>0) {
                [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:self.viewConfiSets.attributeColor] range:range];
            }
        }
        self.rightContentView.attributedText = attStr;
    }
}

-(void)setBaseAttriString:(NSAttributedString *)baseAttriString{
    self.rightContentView.attributedText = baseAttriString;
}

@end
